package com.acwing.partition13;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2022/2/26 15:00
 */
public class AC1241外卖店优先级 {

    private static final int N = 100010;
    private static int[][] orders = new int[N][2];
    private static int[] last = new int[N], score = new int[N];
    private static boolean[] st = new boolean[N];

    private static int n, m, t;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        n = Integer.parseInt(ss[0]);
        m = Integer.parseInt(ss[1]);
        t = Integer.parseInt(ss[2]);
        for (int i = 0; i < m; i++) {
            ss = reader.readLine().split(" ");
            int a = Integer.parseInt(ss[0]), b = Integer.parseInt(ss[1]);
            orders[i] = new int[]{a, b};
        }
        writer.write(resolve() + "\n");
        writer.flush();
    }

    private static int resolve() {
        //按照时间点进行排序，如果时间点相同，则按照商家店铺进行排序
        Arrays.sort(orders, 0, m, (o1, o2) -> o1[0] != o2[0] ? Integer.compare(o1[0], o2[0]) : Integer.compare(o1[1], o2[1]));
        //每次批处理同一个时刻的同一个商家的所有订单
        for (int i = 0; i < m; ) {
            int j = i;
            while (j < m && orders[i][0] == orders[j][0] && orders[i][1] == orders[j][1]) j++;
            int t = orders[i][0], id = orders[i][1], cnt = j - i;
            i = j;
            //统一处理当前时刻之前的信息
            score[id] -= t - last[id] - 1;
            if (score[id] < 0) score[id] = 0;
            if (score[id] <= 3) st[id] = false;
            //处理当前时刻的信息
            score[id] += cnt * 2;
            if (score[id] > 5) st[id] = true;
            last[id] = t;
        }
        //处理一下最后的时刻
        for (int i = 1; i <= n; i++) {
            if (last[i] != t) {
                score[i] -= t - last[i];
                if (score[i] <= 3) st[i] = false;
            }
        }
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            if (st[i]) ans++;
        }
        return ans;
    }
}
